<?php

class Loadmore extends Controller {
	
	function Loadmore()
	{
		//Constructor  
		parent::Controller();
		
		//Check Login
		loginRequired('login');
		
		$this->load->model('usermodel');
		$this->load->model('friendsmodel');
		$this->load->model('wallmodel');
		$this->load->model('uploadmodel');
		$this->load->model('photomodel');
		$this->load->model('blogmodel');
		$this->load->library('form_validation');
	}

	function more()
	{
		$lastmsg = $this->input->post('lastmsg');
		$wall = $this->wallmodel->ajax_more($this->session->userdata('userId'), 'wall_date desc', '0', '9', $lastmsg);
		foreach($wall as $arr): 
		if($arr['wall_type'] == 'action')
			{
				echo $arr['wall_content'] . '<hr />';
			}
			elseif($arr['wall_type'] == 'normal')
			{
?>
<h2>
<a href="<?=base_url() . 'user/id/' . $arr['user_id'];?>"><img width="32px" height="35px" src="<?=$this->usermodel->getAvatar($arr['user_id']);?>"><?=$arr['username'];?></a>
</h2>
<?=$arr['wall_content'] . '<h6>' . $this->usermodel->relativeTime($arr['wall_date']) . '&nbsp;&#183;&nbsp;'; ?><a href="javascript:if(confirm('Are you sure you want to delete this post?')==true){window.location='profile/deleteWall/<?=$arr['wall_id'];?>';}">ลบ</a></h6>

<div id='wallpost'>
	<h5>แสดงความคิดเห็น &nbsp;</h5>
	<div>
	<p>
	<?php echo form_open('profile/subWallPost/'.$arr["wall_id"]);?>
	<input name='comment' type='text' size='40'>
	<label></label>
	<input type='submit' class='button' value='เขียนความคิดเห็น'>
	</form>
	</p>
	</div>
</div>
<? } ?>

<div class='subitem'>
<?php 
$subWall = $this->wallmodel->getSubWall($arr['wall_id']); 
foreach ($subWall as $sub): 
?>
<p>
<h4>
<a href="<?=base_url() . 'user/id/' . $sub['user_id'];?>"><img width="32px" height="35px" src="<?=$this->usermodel->getAvatar($sub['user_id']);?>"><?=$sub['username'];?></a>
</h4>
<?=$sub['sub_wall_content']; ?><a href="javascript:if(confirm('Are you sure you want to delete this comment?')==true){window.location='profile/deleteSubWall/<?=$sub['sub_wall_id'];?>';}">
<h6>
<?=$this->usermodel->relativeTime($sub['sub_wall_date']); ?>&nbsp;&#183;&nbsp;ลบความคิดเห็น
</h6>
</a>
</p>

<?php endforeach;?>
</div>
<label></label>

<?php endforeach;?>
</div>
<div id="more<?php echo @$arr['wall_id']; ?>" class="morebox">
<a href="#" class="more" id="<?php echo @$arr['wall_id']; ?>">ดูเพิ่มเติม</a>
</div>
<?
	}
}
?>
